package utils;

import java.util.ArrayList;
import java.util.List;

import models.Region;
import services.RegionLevelRelationService;

public class RegionTreeUtil {
	public static List<Node> getRegionsTree(){
		List<Node> nodes=new ArrayList<Node>();
		List<Region> lists=RegionLevelRelationService.getFRegion();
		for(Region region : lists){
			List<Node> childNode=new ArrayList<Node>();
			List<Region> children=RegionLevelRelationService.getSRegions(region.id);
			for(Region m : children){
				List<Node> sNodes=new ArrayList<Node>();
				List<Region> Regions=RegionLevelRelationService.getSRegions(m.id);
				for(Region rg : Regions){
					Node n=new Node(rg.id,rg.text,"open",false,null,null);
					sNodes.add(n);
				}
				Node n=new Node(m.id,m.text,"closed",false,null,sNodes);
				childNode.add(n);
			}
			Node node=new Node(region.id,region.text,"closed",false,"",childNode);
			nodes.add(node);
		}
		return nodes;
	}
	
}
